package cn.lger.icollege.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import javax.persistence.Embeddable;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.io.Serializable;

/**
 * Code that Changed the World
 * Pro said
 * Created by Pro on 2018-05-01.
 */
//@Entity
@Data
public class AttendanceCount implements Serializable{

    @Id
    private UnionId id;

    private Integer okNum = 0;

    private Integer lateNum = 0;

    private Integer parseNum = 0;

    private Integer noNum = 0;

    public void setOkNum(Integer okNum) {
        this.okNum = okNum<0?0:okNum;
    }

    public void setLateNum(Integer lateNum) {
        this.lateNum = lateNum<0?0:lateNum;
    }

    public void setParseNum(Integer parseNum) {
        this.parseNum = parseNum<0?0:parseNum;
    }

    public void setNoNum(Integer noNum) {
        this.noNum = noNum<0?0:noNum;
    }

    public AttendanceCount(String teacherId,String studentId){
        this.id=new UnionId(teacherId,studentId);
    }

    public AttendanceCount(){

    }

    @Embeddable
    @Data
    public static class UnionId implements Serializable {

        @JoinColumn(name = "studentId", referencedColumnName = "username")
        @JsonIgnore
        @ManyToOne
        private Student student;

        @JoinColumn(name = "teacherId", referencedColumnName = "username")
        @JsonIgnore
        @ManyToOne
        private Teacher teacher;


        public UnionId(String teacherId,String studentId){
            Student student=new Student();
            student.setUsername(studentId);
            Teacher teacher=new Teacher();
            teacher.setUsername(teacherId);
            this.student=student;
            this.teacher=teacher;
        }

        public UnionId(){}

    }

}
